package offer;

import java.util.LinkedList;

public class offerII_0055 {
    class BSTIterator {
        LinkedList<TreeNode> list=new LinkedList<>();
        boolean flag;
        public BSTIterator(TreeNode root) {
            flag=false;
            setList(root,list);
        }
        private void setList(TreeNode node, LinkedList<TreeNode> list){
            if(node==null) return;
            setList(node.left,list);
            list.add(node);
            setList(node.right,list);
        }
        public int next() {
            if(!flag){
                flag=true;
                return list.removeFirst().val;
            }
            return list.removeFirst().val;
        }

        public boolean hasNext() {
            if(!list.isEmpty()||!flag) return true;
            return false;
        }
    }
}
